﻿using HSGD.Common;

public static class ApplicationConfiguration {
    public static WebApplication ConfigureMiddleware(this WebApplication app) {
        if (app.Environment.IsDevelopment()) {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        ConfigureAuthAndCors(app);

        ConfigureStaticFiles(app);

        app.MapControllers();

        return app;
    }

    private static void ConfigureAuthAndCors(WebApplication app) {
        app.UseCors(AppSettings.app(["Startup", "Cors", "PolicyName"]));
        app.UseAuthentication();
        app.UseAuthorization();
    }

    private static void ConfigureStaticFiles(WebApplication app) {
        var defaultFilesOptions = new DefaultFilesOptions();
        defaultFilesOptions.DefaultFileNames.Clear();
        defaultFilesOptions.DefaultFileNames.Add("index.html");
        app.UseDefaultFiles(defaultFilesOptions);
        app.UseStaticFiles();
    }
}